<template>
	<view class="page">
		<u-navbar  placeholder autoBack bgColor="transparent" leftIconColor="#fff">
			<view class="font-28 font-weight-bold" slot="center">我的推广码</view>
		</u-navbar>
		
		
		<view class="qrcode flex flex-column align-center bg-white mt-3 mx-5">
			<view style="margin-top: 60rpx;">
				<image class="img"  :src="qrcode" mode=""></image>
			</view>
			<!-- <view class="font-28 text-light7F mt-5">我的推广码</view>
			<view class="font-28 mt-1" style="color: #04BF79;">{{invite_code}}</view> -->
			<!-- 操作 -->
			<view class="flex align-center justify-center stockpile my-3" @click="saveImage">
				保存到相册
			</view>
			<!-- 提示 -->
			<view class="font-28 titltColor">
				<!-- <view class="">
					1.邀请好友收益说明后台添加遵请好友收益
				</view>
				<view class="">
					2.说明后台添加
				</view>
				<view class="">
					3.请好友收益说明后台添加邀请好友收益
				</view> -->
			</view>
		</view>
	</view>
</template>

<script>
	import QR from '@/utils/qrcode.js';
	import {
		base
	} from '@/request/env.js'
	export default {
		data() {
			return {
				qrcode:""
			};
		},
		onLoad() {
			this.getData()
			
		},
		methods:{
			getData() {
				this.$api.qrcode().then(res => {
					console.log(res)
					if (res.code === 1) {
						
						console.log(uni.$u.platform);
						//this.qrcode = uni.$u.platform == 'mp'? base + res.data.invitation_image:base+'image/wx.png'
						this.qrcode = base + res.data.invitation_image
						console.log(this.qrcode)
					}
				})	
				
			},
			saveImage() {
				uni.downloadFile({
					url: this.qrcode,
					success: (res) => {
						if(uni.$u.platform === 'mp'){
							uni.authorize({
								scope:'scope.writePhotosAlbum',
								success() {
									uni.saveImageToPhotosAlbum({
										filePath: res.tempFilePath,
										success: (result) => {
											uni.showToast({
												title: '保存成功',
												icon: 'success'
											})
										}
									})
									
								}
							})
						}else{
							uni.saveImageToPhotosAlbum({
								filePath: res.tempFilePath,
								success: (result) => {
									uni.showToast({
										title: '保存成功',
										icon: 'success'
									})
								}
							})
						}
						
					}
				})
			}
		}
	}
</script>

<style lang="scss">
page{
	width: 100%;
	height: 100%;
	background: linear-gradient(to right bottom,#d0f2e5 ,#edfbdb,#a7f4a6);
	
	.qrcode{
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		opacity: 1;
		
		.img{
			width: 444rpx;
			height: 444rpx;
		}
		
		.stockpile {
			width: 440rpx;
			height: 90rpx;
			background-color: #81ee81;
			border-radius: 45rpx;
		}
		
		.titltColor {
			color: #8a8a8a;
			margin-bottom: 90rpx;
			line-height: 44rpx;
		}
	}
	
	
	
}
</style>
